    new MusicTalk();
    new MusicBrainz();
    new SmoothScroll({ duration: 600 });
    
    Add = {
    /*CHECKLINK_____________________________________________________________________________________
    Check if the link contains a valid mp3*/
    checkLink: function (url_){
     var url = url_?url_:$('url').getValue().trim();

     $('track_form_wrapper').setStyle('height',''); 
     $('response').effect('opacity',{duration:600, onComplete: function(){$('response').setStyle('display','none')}}).start(0);
     var target = $('track_summary');
     mt.track.setTarget(target);     
     mt.track.callback = function(url, error){
       if(error){
         mt.track.target.innerHTML = '<div class="errors">While checking the link you provided we encountered this error: <strong>'+error.value+'</strong><br />Please check  &amp; edit your link in the field below</div>'+
         '<form class="form" onsubmit="Add.checkLink($(\'url2\').getValue().trim())"><p><span>URL <small>(beginning with http://)</small>:</span><input id="url2" name="url2" type="text" size="35" value="'+url+'"/></p><div style="text-align:right;"><input type="submit" value="Save changes" style="margin-top:15px;"/></div></form>';
       }
       else{
         mt.track.target.innerHTML = 'Verifying the link provided... <a href="'+url+'">OK</a>';
         $('article').setOpacity(0).setStyle('display','block');
         $('article').effect('opacity',{duration:600}).start(1);
      }
     }
     try{    mt.track.checkLink(url);         
     }      
     catch(e){ alert(e)  }
    } ,
  /*RESET_______________________________________________________________________________________
  resets the track form*/
  reset: function(showList) {

  $('submit_track').disabled = false;
  
  if(!showList) $('response').effect('opacity',{duration:600}).start(0);
  var _duration = $('track_form_wrapper').getStyle('height')=='0px'?0:500;
    
  $('track_form_wrapper').effect('height', {duration: _duration, 
    onComplete: function(){
      try{$('track_summary').remove();}
      catch(e){ } 
      $('track_form').setStyle('display',''); 
      var height = $('track_form').getSize().size.y;
  
      $('track_form_wrapper').effect('height', {duration: 500, 
        onCLomplete: function(){$('title').focus().select();}
      }).start(height);
    }
  }).start(0);
},
/*SELECT_______________________________________________________________________________________
  select a track from the list*/
   select: function(index){
   mt.track.select(index);
    var html = '<h3>You are about to add this song:</h3>';
    html += '<div class="moreinfo">You can still change your selection by choosing a track from the list below</div><p><strong>'+mt.track.info[index].title+'</strong>, by '+mt.track.info[index].artist+'<br />from: <i>'+(mt.track.info[index].release?mt.track.info[index].release:'N/A')+'</i>';
    var div = $('track_summary')?$('track_summary'):new Element('div',{'id': 'track_summary'});
    html += '<div style="text-align:right;font-size:120%;margin-top:20px;"><form class="form"><input type="button" onclick="Add.reset()" value="Cancel" />  |  <input type="button" onclick="Add.checkLink()" value="Add this song!" /></form></div>'
  
  if($('track_form').getStyle('display') != 'none') {
    div.setStyle('display','none');
    div.injectBefore($('track_form'));
  }
  
  var height = 190;

  if($('track_form').getStyle('display') != 'none'){
        $('track_form').setStyle('display','none');
        div.innerHTML = html;
        div.setStyle('display','block');
        $('track_form_wrapper').effect('height', {duration: 500, onComplete: function(){$('track_form_wrapper').setStyle('height','');} }).start(height);
        
  }
  else{  
    $('track_form_wrapper').effect('height', {duration: 400, 
      onComplete: function(){
        div.innerHTML = html;
        div.injectBefore($('track_form'));
        $('track_form_wrapper').effect('height', {duration: 300, onComplete: function(){$('track_form_wrapper').setStyle('height','');}}).start(height);}
    }).start(0);
   }   
  },
  /*ADD_________________________________________________________________________
  * adds the track to the DB
  */
  add: function(){
    try{
    var target = $('track_summary');
    mt.track.setTarget(target);
    mt.track.callback = function(id, error){
      if(error){
        if(error.msg == 'ERROR_FIELDS'){
          eval('var errors = '+error.value);                  
          mt.showError(errors, $('track_form'));
          $('track_form').setStyle('display','');
          mt.track.target.innerHTML = '';
        }
        else
          mt.track.target.innerHTML = '<strong>Ooops!</strong> Something went wrong :(<br />';
      }
      else{
        mt.track.target.innerHTML = '';
        Add.finished(id);
      }
    }

   mt.track.add();
       
   $('article').effect('opacity',{duration:600, onComplete: function() { $('article').setStyle('display','none'); }}).start(0);
    }catch(e){ alert(e)  }
  },
  /*
  FINISHED______________________________________________________________
  final screeen
  */
  finished: function(track_id){
    $('track_success_added').innerHTML = '<strong>'+mt.track.info[mt.track.index]['title']+'</strong> has been succesfully added!'+$('track_success_added').innerHTML;
    $('track_success_added_form').setAttribute('action','/track/listen/'+track_id);
    $('track_success_added').setOpacity(0).setStyle('display','block');
    $('track_success_added').effect('opacity',{duration:600}).start(1);			
  },
   /*
  FORCE______________________________________________________________
  force the addition af a track bypassing musicbrainz
  */
  force: function(hideList){
    mt.track.force();
    if(hideList) $('response').effect('opacity',{duration:600}).start(0);
    Add.select(0);
  }
}

    window.addEvent('domready', function(){
    
    $('track_form').addEvent('submit', function(e) {
        //Prevent the submit event
        new Event(e).stop();
        
        var errors = {};
        if(! $('url').getValue().trim().match(/^http:\/\/([a-z0-9_\.%-])+\.[a-z]{2,4}\/([a-z0-9_\.%~\/,?-])+\.mp3$/i)) errors['url']='The URL provided is not valid.';
        if(! $('title').getValue().trim().length) errors['title']='The song title has to be at least one charachter long!';
        if(! $('artist').getValue().trim().length) errors['artist']='The artist name has to be at least one charachter long!';
                
        if(mt.showError(errors, 'track_form'))
          return;
        
        $('submit_track').disabled = true;
        //$('track_form').addClass('disable');
        $('track_form_wrapper').effect('height', {duration: 800}).start(0);        
        mb.setTarget('response_c');
        
       $('response').setStyles('display','block', 'visibility','visible').effect('opacity',{duration:600}).start(1);
       mb.search($('artist').getValue().trim(),$('title').getValue().trim());
      });
    $('article_body').addEvent('click',function(e){
      if($('article_body').value=='Type here') $('article_body').value ='';    
      }
    );
    });
